package com.my.yc.d0219;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/getWeek.s")
public class GetWeekServlet extends HttpServlet {

    /*
        1.  继承 ==> 身份
        2.  重写 ==> 业务
        3.  配置 ==> 安装   注解
     */
    // 单实例运行
    private int a = 1;

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

       a++;

        Date date = new Date();
        String code = req.getParameter("code");
        if (code == null){
            code = "EEE";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(code);
        final String format = sdf.format(date);
        resp.setContentType("text/html;charset=utf-8");

        resp.getWriter().printf("第%d次访问:" ,a);
        resp.getWriter().print(format);
    }
}
